package com.example.april.controller;

import com.example.april.pojo.Customer;
import com.example.april.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class UDIController {

    @Autowired
    CustomerService customerService;

    @RequestMapping("/update")
    public String update(@RequestParam String id, Model model){
        Customer customer = customerService.update(id);
        model.addAttribute("customer",customer);
        return "/update";
    }
    @GetMapping("/subUpdate")
    public String subUpdate(Customer customer){
        customerService.subUpdate(customer);
        return "redirect:/index";
    }

    @RequestMapping("/delete")
    public String delete(@RequestParam String id){
        customerService.delete(id);
        return "redirect:/index";
    }

    @RequestMapping("/toInsert")
    public String toInsert(){
        return "insert";
    }
    @RequestMapping("/insert")
    public String insert(Customer customer){
        customerService.insert(customer);
        return "redirect:/index";
    }
}
